/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormCursoDinamico.java
 *
 * Created on 25/01/2012, 11:01:27
 */
package Formularios;

import Atributos.Curso;
import Atributos.Disciplina;
import Metodos.CursoMet;
import Metodos.DisciplinaMet;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

/**
 *
 * @author Andre
 */
public class FormCursoDinamico extends javax.swing.JFrame {
 DisciplinaMet discmet=new DisciplinaMet();
 private List<Disciplina> listaD;
    Curso curso=new Curso();
 CursoMet cursomet=new CursoMet();
 String a,b,c,d,e,f,g,h,i,j,k;
        String jrb[]={a,b,c,d,e,f,g,h,i,j,k};
        private List<Curso> lista;
        private String[] nomes_cursos,descrição;
    public FormCursoDinamico() {
        initComponents();
        BufferedImage image=null;
        File imageFile=new File(".\\src\\Imagens\\logo3.png");
        try {
            image=ImageIO.read(imageFile);
            
        } catch (IOException ex) {
        }
        this.setIconImage(image);
        
//        BufferedImage image=new BufferedImage(10,10,BufferedImage.TYPE_INT_ARGB);
//        setIconImage(image);
        AtualizaDados();
        SequenciaIFs();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jPanel1 = new javax.swing.JPanel();
        jRB_1 = new javax.swing.JRadioButton();
        jRB_2 = new javax.swing.JRadioButton();
        jRB_3 = new javax.swing.JRadioButton();
        jRB_4 = new javax.swing.JRadioButton();
        jRB_5 = new javax.swing.JRadioButton();
        jRB_6 = new javax.swing.JRadioButton();
        jRB_7 = new javax.swing.JRadioButton();
        jRB_8 = new javax.swing.JRadioButton();
        jRB_9 = new javax.swing.JRadioButton();
        jRB_10 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cursos");
        setResizable(false);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
                formWindowLostFocus(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setLayout(null);

        jRB_1.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_1);
        jRB_1.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_1.setForeground(new java.awt.Color(255, 102, 0));
        jRB_1.setFocusPainted(false);
        jPanel1.add(jRB_1);
        jRB_1.setBounds(20, 10, 190, 21);

        jRB_2.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_2);
        jRB_2.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_2.setForeground(new java.awt.Color(255, 102, 0));
        jRB_2.setFocusPainted(false);
        jPanel1.add(jRB_2);
        jRB_2.setBounds(20, 40, 190, 27);

        jRB_3.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_3);
        jRB_3.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_3.setForeground(new java.awt.Color(255, 102, 0));
        jRB_3.setFocusPainted(false);
        jPanel1.add(jRB_3);
        jRB_3.setBounds(20, 70, 190, 27);

        jRB_4.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_4);
        jRB_4.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_4.setForeground(new java.awt.Color(255, 102, 0));
        jRB_4.setFocusPainted(false);
        jPanel1.add(jRB_4);
        jRB_4.setBounds(20, 100, 190, 27);

        jRB_5.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_5);
        jRB_5.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_5.setForeground(new java.awt.Color(255, 102, 0));
        jRB_5.setFocusPainted(false);
        jPanel1.add(jRB_5);
        jRB_5.setBounds(20, 130, 190, 27);

        jRB_6.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_6);
        jRB_6.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_6.setForeground(new java.awt.Color(255, 102, 0));
        jRB_6.setFocusPainted(false);
        jPanel1.add(jRB_6);
        jRB_6.setBounds(20, 160, 190, 27);

        jRB_7.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_7);
        jRB_7.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_7.setForeground(new java.awt.Color(255, 102, 0));
        jRB_7.setFocusPainted(false);
        jPanel1.add(jRB_7);
        jRB_7.setBounds(20, 190, 190, 27);

        jRB_8.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_8);
        jRB_8.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_8.setForeground(new java.awt.Color(255, 102, 0));
        jRB_8.setFocusPainted(false);
        jPanel1.add(jRB_8);
        jRB_8.setBounds(20, 220, 190, 27);

        jRB_9.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_9);
        jRB_9.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_9.setForeground(new java.awt.Color(255, 102, 0));
        jRB_9.setFocusPainted(false);
        jPanel1.add(jRB_9);
        jRB_9.setBounds(20, 250, 190, 27);

        jRB_10.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_10);
        jRB_10.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        jRB_10.setForeground(new java.awt.Color(255, 102, 0));
        jRB_10.setFocusPainted(false);
        jPanel1.add(jRB_10);
        jRB_10.setBounds(20, 280, 190, 27);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/OKlay1.jpg"))); // NOI18N
        jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        jPanel1.add(jLabel1);
        jLabel1.setBounds(130, 330, 71, 52);

        jPanel1.setBounds(0, 0, 230, 420);
        jDesktopPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-446)/2, 237, 446);
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
       if(buttonGroup1.getSelection()!=null){
           if(cursomet.Buscar_Se_Ha_Curso()){
           if(jRB_1.isSelected()){
               listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_1.getText(),null);
             if(!listaD.isEmpty()){  
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_1.getText(),null,1).setVisible(true);
           }
              });
             }else{
               JOptionPane.showMessageDialog(null, "Não há disciplinas cadastradas neste curso");  
             }
           }
            if(jRB_2.isSelected()){
            listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_2.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_2.getText(),null,1).setVisible(true);
           }
              });
             }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
             if(jRB_3.isSelected()){
                  listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_3.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_3.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
              if(jRB_4.isSelected()){
              listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_4.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_4.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
               if(jRB_5.isSelected()){
              listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_5.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_5.getText(),null,1).setVisible(true);
           }
              });
             }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
                if(jRB_6.isSelected()){
                    listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_6.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_6.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
                 if(jRB_7.isSelected()){
                     listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_7.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_7.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
                  if(jRB_8.isSelected()){
                      listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_8.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_8.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
                   if(jRB_9.isSelected()){
                       listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_9.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_9.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
                    if(jRB_10.isSelected()){
                        listaD=discmet.Buscar_Nome_DisciplinasProf(jRB_10.getText(),null);
             if(!listaD.isEmpty()){
              java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {                
                        new FormDisc_Dinamico(jRB_10.getText(),null,1).setVisible(true);
           }
              });
              }else{
               JOptionPane.showMessageDialog(null, "Não ha disciplinas cadastradas neste curso");  
             }
                      }
           }
       }else{
           JOptionPane.showMessageDialog(null, "Nada foi selecionado!");
       }
    }//GEN-LAST:event_jLabel1MouseClicked

    private void formWindowLostFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowLostFocus
       dispose();
    }//GEN-LAST:event_formWindowLostFocus

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new FormCursoDinamico().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRB_1;
    private javax.swing.JRadioButton jRB_10;
    private javax.swing.JRadioButton jRB_2;
    private javax.swing.JRadioButton jRB_3;
    private javax.swing.JRadioButton jRB_4;
    private javax.swing.JRadioButton jRB_5;
    private javax.swing.JRadioButton jRB_6;
    private javax.swing.JRadioButton jRB_7;
    private javax.swing.JRadioButton jRB_8;
    private javax.swing.JRadioButton jRB_9;
    // End of variables declaration//GEN-END:variables

    private void AtualizaDados() {
        if(cursomet.Buscar_Se_Ha_Curso()){  
        
    String[] cursos = cursomet.Buscar_Nome_Cursos();
    
    int ind=0;
    
    
    while(cursos.length>ind)
    {  
       
       jrb[ind]=cursos[ind];
        System.out.println(cursos[ind]);
        ind++;
    }
    jRB_1.setText(jrb[0]);
    jRB_2.setText(jrb[1]);
    jRB_3.setText(jrb[2]);
    jRB_4.setText(jrb[3]);
    jRB_5.setText(jrb[4]);
    jRB_6.setText(jrb[5]);
    jRB_7.setText(jrb[6]);
    jRB_8.setText(jrb[7]);
    jRB_9.setText(jrb[8]);
    jRB_10.setText(jrb[9]);
        }
    }

    private void SequenciaIFs() {
        if( jRB_1.getText()==null){
        jRB_1.setVisible(false);
        JOptionPane.showMessageDialog(null, "Não ha cursos a serem escolhidos");
        dispose();
    }else{
        jLabel1.setBounds(130, 60, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-160)/2, 237, 160);
        }
    if( jRB_2.getText()==null){
        jRB_2.setVisible(false);

    }else{
        jLabel1.setBounds(130, 80, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-180)/2, 237, 180);
    }
    if( jRB_3.getText()==null){
        jRB_3.setVisible(false);

    }else{
        jLabel1.setBounds(130, 100, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-200)/2, 237, 200);
        }
    if( jRB_4.getText()==null){
        jRB_4.setVisible(false);

    }else{
        jLabel1.setBounds(130, 120, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-220)/2, 237, 220);
        }
    if( jRB_5.getText()==null){
        jRB_5.setVisible(false);

    }else{
        jLabel1.setBounds(130, 160, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-240)/2, 237, 240);
        }
    if( jRB_6.getText()==null){
        jRB_6.setVisible(false);

    }else{
        jLabel1.setBounds(130, 180, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-260)/2, 237, 260);
        }
    if( jRB_7.getText()==null){
        jRB_7.setVisible(false);

    }else{
        jLabel1.setBounds(130, 210, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-290)/2, 237, 290);
        }
    if( jRB_8.getText()==null){
        jRB_8.setVisible(false);

    }else{
        jLabel1.setBounds(130, 240, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-320)/2, 237, 320);
        }
    if( jRB_9.getText()==null){
        jRB_9.setVisible(false);

    }else{
        jLabel1.setBounds(130, 270, 71, 52);
        
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-350)/2, 237, 350);
        }
    if( jRB_10.getText()==null){
        jRB_10.setVisible(false);

    }else{
        jLabel1.setBounds(130, 300, 71, 52);
         
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-237)/2, (screenSize.height-380)/2, 237, 380);
        }
    }

    
}
